<?require_once("connection.php");?>
<table>
	<tbody>
		<tr>
			<td>Course Name</td>
			<?
			if($_POST["oper"]==0)
				echo "<td><input id='name' type='text' size='40' maxlength='100'/></td>";
			else
				if($_POST["oper"]==1){
				$query = "select * from g_courses where course_id=".$_POST["rec"].";";
				$result =@mysql_query($query);
				$row_edit = @mysql_fetch_array($result);
				echo "<td><input id='name' value='".$row_edit["name"]."' type='text' size='40' maxlength='100'/></td>";
			}
			?>
		</tr>
		<!--<tr>
      <td>verseBody</td>
      <td>
      <?
        if($_GET["oper"]==0)
          echo "<textarea id='verse_body' rows='20' cols='120'></textarea>";
        else
          if($_GET["oper"]==1){
            echo "<textarea id='verse_body' rows='20' cols='120'>".$row_edit["verseBody"]."</textarea>";
          }
      ?>
      </td>
    </tr>-->
		<tr>
			<td>Year</td>
			<?
			if($_POST["oper"]==0)
				echo "<td><input id='year' type='text' size='40' maxlength='4'/></td>";
			else
				if($_POST["oper"]==1){
				echo "<td><input id='year' value='".$row_edit["year"]."' type='text' size='40' maxlength='4'/></td>";
			}
			?>
		</tr>
		<tr>
			<td>Semester</td>
			<td><?
			/*if($_POST["oper"]==0)
			 echo "<td><input id='semester' type='text' size='40' maxlength='100'/></td>";
			else
				if($_POST["oper"]==1){
			echo "<td><input id='semester' value='".$row_edit["semester"]."' type='text' size='40' maxlength='100'/></td>";
			}*/
			?> <?
			echo "<select id='semester' style='width:200px'>";
			echo "<option value='0'>Choose Semester</option>";
			if($_POST["oper"]==0){
				echo "<option value='1'>Spring</option>";
				echo "<option value='2'>Fall</option>";
			}
			else
				if($_POST["oper"]==1){
				if($row_edit["semester"]=="Spring"){
					echo "<option value='1' selected>Spring</option>";
					echo "<option value='2' >Fall</option>";
				}
				else{
					echo "<option value='1' >Spring</option>";
					echo "<option value='2' selected>Fall</option>";
				}
			}
			echo "</select>";
	  ?>
			</td>
		</tr>
		<tr>
			<td>Instructors</td>
			<td><?
			echo "<select id='instructors' style='width:200px' onChange='instructors_onChange();'>";
			echo "<option value='0'>Choose Instructors</option>";
			//if($_POST["oper"]==0)
			//{
				$query = "select ID,user_login from  wp_users;";
				$result =@mysql_query($query);
				while($user = @mysql_fetch_array($result))
				{
					echo "<option value='".$user['ID']."' >".$user['user_login']."</option>";
				}
			//}?>
			</td>
			<td>
				<button id='addInstructor' onclick='<? if($_POST["oper"]==0) 
															echo 'addInstructor()';
													   elseif ($_POST["oper"]==1)
													   	 echo "addCourseStaff(".$_POST["rec"].")";?>' disabled="true">+</button>
			</td>
		</tr>
		<tr>
			<td></td>
			<td>
				<!-- Dynamically display the staff course relation -->
				<table id="tblInstructor">
					<tbody>
						<?php 	
						if($_POST["oper"]==1){
							$query = "SELECT g_staff_course.course_id,g_staff_course.staff_id, wp_users.user_login
							FROM wp_users
							INNER JOIN g_staff_course
							ON wp_users.ID=g_staff_course.staff_id
							WHERE g_staff_course.course_id=".$_POST["rec"].";";
							$result =@mysql_query($query);
							while($user = @mysql_fetch_array($result))
							{
								echo "<tr id='".$user["staff_id"]."'>
										<td>
										<a href='#' onclick='deleteCourseStaff(".$_POST["rec"].",".$user["staff_id"].")'>
										<img border='0' alt='Delete' src='../wp-content/plugins/course_management/images/delete.png'/></a>
										</td><td>".$user["user_login"]."</td>";
							}
						}
						?>
					</tbody>
				</table>
			</td>
		</tr>
		<tr>
			<td>Content</td>
			<?
			if($_POST["oper"]==0)
				echo "<td><textarea id='content' rows='7' cols='60' ></textarea></td>";
			else
				if($_POST["oper"]==1){
				echo "<td><textarea id='content' rows='7' cols='60'>".$row_edit["content"]."</textarea></td>";
			}
			?>
		</tr>
		<!--<tr>
          <td></td>
          <td><textarea id="wpet_options[textarea_three]" name="wpet_options[textarea_three]" rows="7" cols="150" type='textarea'><?php echo $options['textarea_three']; ?></textarea></td>
		</tr>-->
		<!--    <tr>
      <td>visible</td>
      <td>
      <?
        if($_GET["oper"]==0)
          echo "<input id='visible' type='checkbox'/>";
        else
          if($_GET["oper"]==1){
            if($row_edit["visible"]==0)
              echo "<input id='visible' type='checkbox'/>";
            else
              echo "<input id='visible' type='checkbox' checked/>";
          }
      ?>
      </td>
    </tr>
    <tr>
      <td>personName</td>
      <td>
	  <?
	    $query = "select * from person;";
	    $result = @mysql_query($query);
	    echo "<select id='person_name'>";
	    echo "<option value='0'>Та".$kaz['4']."да".$kaz['4']."ыз</option>";
	    while($row=@mysql_fetch_array($result)){
	      if($_GET["oper"]==0)
	        echo "<option value='".$row["personID"]."'>".$row["personName"]."</option>";
          else
            if($_GET["oper"]==1){
              if($row["personID"]==$row_edit["personID"])
                echo "<option value='".$row["personID"]."' selected>".$row["personName"]."</option>";
              else
                echo "<option value='".$row["personID"]."'>".$row["personName"]."</option>";
            }
	    }
	    echo "</select>";
	  ?>
      </td>
    </tr>
    <tr>
      <td>groupName</td>
      <td>
	  <?
	    $query = "select * from groups;";
	    $result = @mysql_query($query);
	    echo "<select id='group_name'>";
	    //echo "<option value='0'>Та".$kaz['4']."да".$kaz['4']."ыз</option>";
	    while($row=@mysql_fetch_array($result)){
	      if($_GET["oper"]==0)
	        echo "<option value='".$row["groupID"]."'>".$row["groupName"]."</option>";
          else
            if($_GET["oper"]==1){
              if($row["groupID"]==$row_edit["groupID"])
                echo "<option value='".$row["groupID"]."' selected>".$row["groupName"]."</option>";
              else
                echo "<option value='".$row["groupID"]."'>".$row["groupName"]."</option>";
            }
	    }
	    echo "</select>";
	  ?>
      </td>
    </tr>-->
		<tr>
			<td>&nbsp</td>
			<td align="right"><?
			echo "<button onclick='display_table(1,0);return false;'>Back</button>";
			if($_POST["oper"]==0)
				echo "<button onclick='save_course(0,0);return false;'>Add</button>";
			else
				if($_POST["oper"]==1)
				echo "<button onclick='save_course(1, ".$_POST["rec"].");return false;'>Edit</button>";
			?>
			</td>
		</tr>
	</tbody>
</table>
